home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFlist. Part 1 of 2.
- *
- * Version 2.0, 9-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 29-Jan-91, H Leckner Original version (for CDF V2.0).
- * V1.1 5-Feb-91, J Love Modified error handling.
- * V1.2 12-Feb-91, H Leckner Fixed variable name handling.
- * V1.3 13-Mar-91, H Leckner Fixed attribute entry problem.
- * V1.4 20-Mar-91, H Leckner Fixed problem with large dimension sizes.
- * V1.5 26-Mar-91, J Love Cast malloc calls to proper type. Fix for
- * possible char array overwrite.
- * V1.6 4-Apr-91, H Leckner Fixed problem with filtering REAL8 values.
- * V1.7 5-Jun-91, S Sudarsan Enhanced file/directory input handling
- * along with file_names.c. Changed logical
- * name for HELP directory.
- * V1.8 25-Jun-91, J Love Added QOP. Added CDF_EPOCH as a data type.
- * H Leckner Added #include <sys/types.h>.
- * V1.9 12-Jul-91, J Love TRUE/FALSE. Changed for Cray/UNICOS port.
- * H Leckner Added use of VALIDMIN/VALIDMAX for initial
- * filters (if NSSDC_STANDARD). Use 'Exit' &
- * 'ExitBAD'.
- * V1.10 20-Sep-91, H Leckner Fixed window labeling. Modified for IBM-PC
- * J Love port.
- * V1.11 11-Oct-91, H Leckner Added ability to select more than 8
- * variables.
- * V1.12 18-Oct-91, H Leckner Changed for IBM-RS6000 port.
- * V2.0 9-Mar-92, H Leckner IBM PC port. CDF V2.2.
- *
- ******************************************************************************/
-
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #if defined (vms)
- #include <descrip.h>
- #endif
- #if defined(__MSDOS__)
- #include <dos.h>
- int _Cdecl kbhit( void );
- #endif
-
- #define CDFLIST 1
- #include "cdfdist.h"
- #include "wfl.h"
- #include "kb_def.h"
- #include "utility.h"
- #include "cdflist.h"
-
- #if NSSDC_STANDARD
- Boolean initialfilters = TRUE;
- #else
- Boolean initialfilters = FALSE;
- #endif
- Boolean check_epoch(str, scale)
- char str[];
- double *scale;
- {
- static char default_time[] = " 00:00:00.000";
- long int len;
- long int rcode;
- *scale = 0.;
- len = strlen(str);
- if(len == 0)
- return(TRUE);
- else if(len < 11)
- return(FALSE);
- else if(len < 24)
- strcat(str, default_time+(len+2-13));
- rcode = epochParse(str, &ep);
- *scale = ep.tSince0;
- return(rcode);
- }
-
-
- int precision(num)
- double num;
- {
- double abs_value;
- int p;
- abs_value = fabs(num);
- if(abs_value < 1.)
- p = 5;
- else if(abs_value < 10.)
- p = 4;
- else if(abs_value < 10000.)
- p = 3;
- else if(abs_value < 100000.)
- p = 2;
- else
- p = 1;
- return(p);
- }
- int CDFLIST_CDF_name(screen, CDF, field_num, input_type)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- long int *field_num;
- long int *input_type;
- {
- char file_spec[256],temp[256];
- static char save[CDF_PATHNAME_LEN];
- char save_name[CDF_PATHNAME_LEN];
- char save_temp[CDF_PATHNAME_LEN];
- char **directory_list;
- char **result_spec_list;
- int num_files = 0;
- int termcode, i, row;
- int drows;
- long int CDF_num;
- int tcode;
- int done;
- int dir;
- static int first = TRUE;
- char row_data[CDF_COLUMNS];
- #if defined(unix)
- static char curr_dir[] = "./*.cdf" ;
- #else
- #if defined(__MSDOS__)
- static char curr_dir[] = ".\\*.cdf";
- #else
- #if defined(vms)
- static char curr_dir[] = "[]*.cdf";
- #endif
- #endif
- #endif
-
- static char dir_mes[] =
- "Enter Directory and/or CDF name (default=CDFs in current directory)";
- static char dir_error[] = "No CDFs found, reenter directory and/or CDF name";
- static char select_mes[] =
- "Select a CDF or press Q to enter a new Directory/CDF_name";
- struct vid_struct *DIR_display;
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- int new_CDF;
- int regfile;
- int last_error = FALSE;
- strcpy(save_name, C.CDF_name);
- new_CDF= FALSE;
- done = FALSE;
- regfile = FALSE;
- while(!done)
- {
- if(*input_type == MANUAL)
- {
- if(first)
- {
- key_line1[0] = '\0'; key_line2[0] = '\0';
- strcat(key_line1, CNTRLM); strcat(key_line1, RET);strcat(key_line1, CNTRLN);
- strcat(key_line2, CNTRLW);strcat(key_line2, HLP);strcat(key_line2, CNTRLD); /* V1.5 */
- CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
- if(!last_error)
- {
- for (i=0; i < CDF_NAME_LENGTH; i++)
- C.CDF_name[i] = '\0';
- strcpy(C.CDF_name, default_name);
-
- CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- CDFLIST_put_message(S.MES_vid, dir_mes, NOBELL, NORMAL, NOPAUSE);
- input_field(S.CDF_vid, C.CDF_name,
- CDF_NAME_ROW, CDF_NAME_COL, CDF_NAME_LENGTH-COL_OFFSET, &termcode);
- }
- else
- CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
- save, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- else
- termcode = KB_RETURN;
- *input_type = MANUAL;
- first = FALSE;
- last_error = FALSE;
- CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- if(termcode == KB_CTRL_F)
- {
- CDFLIST_field_menu(screen, field_num);
- if((int) (*field_num) != CDF_FIELD)
- {
- done = TRUE;
- tcode = QUIT;
- }
- else
- first = TRUE;
- }
- else
- {
- row = CDF_NAME_ROW;
-
- read_display(S.CDF_vid, row, row_data);
-
- for (i=CDF_NAME_COL; i < CDF_NAME_COL+CDF_NAME_LENGTH-1; i++)
- if(row_data[i-1] != 32)
- temp[i-CDF_NAME_COL] = row_data[i-1];
- else
- temp[i-CDF_NAME_COL] = '\0';
- /*
- Save for next time
- */
- strcpy(save_temp, temp);
-
- strcpy(file_spec, temp);
- if(strlen(file_spec) == 0)
- strcpy(file_spec, curr_dir);
- else
- {
- dir = FALSE;
- strcpy(temp, file_spec);
- strcat(temp,".cdf");
- if(!IsReg(temp))
- {
- regfile = FALSE;
- if(IsDir(file_spec))
- {
- AppendToDir(file_spec, "*.cdf");
- dir = TRUE;
- }
- else
- strcat(file_spec, ".cdf");
- }/* end else */
- else
- {
- regfile = TRUE;
- strcat(file_spec, ".cdf");
- }
- }/* end else */
- num_files = DirList(file_spec, &directory_list, &result_spec_list);
- if(num_files > 0)
- {
- strcpy(save, save_temp);
- RemoveExtensions(num_files, result_spec_list);
- done = TRUE;
- if(num_files == 1 && regfile)
- {
- CDF_num = 1;
- tcode = KB_RETURN;
- first = TRUE;
- }
- else
- {
- /*
- allocate the space for a vid structure which contains the CDF NAMES
- */
- DIR_display = (struct vid_struct *)
- malloc(num_files * sizeof(struct vid_struct));
- if(DIR_display == NULL)return(BAD_MALLOC);
- /*
- Load in the cdf names into the structure
- */
- for (i=0; i<num_files; i++)
- {
- DIR_display[i].row = 1;
- DIR_display[i].col = 1;
- strcpy(DIR_display[i].label, result_spec_list[i]);
- DIR_display[i].field_col = 1;
- }
- if((num_files+ROW_OFFSET) > DIR_ROWS)
- drows = DIR_ROWS;
- else
- drows = num_files + ROW_OFFSET;
- #if defined(vms)
- change_virtual_display(drows, DIR_COLUMNS, S.DIR_vid,
- BORDER, BOLD);
- #else
- change_virtual_display(drows, DIR_COLUMNS, &S.DIR_vid,
- BORDER, BOLD);
- #endif
- CDFLIST_put_message(S.MES_vid, select_mes, NOBELL, NORMAL, NOPAUSE);
- CDFLIST_menu_keydef(screen);
- CDFLIST_select_menu_item(S.DIR_vid,
- S.MES_vid, &CDF_num, DIR_display, num_files, drows,
- DIR_COLUMNS, DIR_ROW_PASTE, DIR_COL_PASTE, MENU, &tcode);
- free (DIR_display);
- } /* end num_files > 1 */
- if(tcode == KB_RETURN)
- {
- if(dir || strlen(directory_list[CDF_num-1]) > 0)
- {
- strcpy(C.CDF_name, directory_list[CDF_num-1]);
- AppendToDir(C.CDF_name, result_spec_list[CDF_num-1]);
- }
- else
- strcpy(C.CDF_name, result_spec_list[CDF_num-1]);
-
- C.CDF_name[CDF_NAME_LENGTH]= '\0';
- CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- new_CDF = TRUE;
- (*field_num)++;
- }
- else
- {
- change_rendition(S.CDF_vid, CDF_NAME_ROW, CDF_NAME_COL, 1,
- strlen(C.CDF_name), REVERSE);
- if(tcode == KB_CTRL_F)
- {
- CDFLIST_field_menu(screen, field_num);
- if((int) (*field_num) == CDF_FIELD)done = FALSE;
- }
- else
- done = FALSE;
- first = TRUE;
- } /* num > 1 */
-
- free (directory_list);
- free (result_spec_list);
- } /*num_file > 0*/
- else
- {
- CDFLIST_put_message(S.MES_vid, dir_error, RINGBELL, NORMAL, PAUSE);
- first = TRUE;
- last_error = TRUE;
- }
- }/*keyboard != C-F*/
- }/*done?*/
- /*
- If a new CDF was not selected put the old one back on the input line
- */
- if(!new_CDF)
- {
- strcpy(C.CDF_name, save_name);
- CDFLIST_put_selection(S.CDF_vid, CDF_display, 0,
- C.CDF_name, CDF_NAME_LENGTH-COL_OFFSET, REVERSE);
- }
- return(tcode);
-
- }
- #ifdef vms
- void CDFLIST_save_screen(screen)
- struct GLOBAL_struct *screen;
- {
- save_screen(&S.save_id);
- }
- void CDFLIST_restore_screen(screen)
- struct GLOBAL_struct *screen;
- {
- restore_screen(S.save_id);
- }
- #endif
- long int get_var_num(possible, mnemonic, num_poss)
- struct variable_struct possible[];
- char *mnemonic;
- long int num_poss;
- {
- long int i;
- long int var_num;
- long int size;
- var_num = NOTTHERE;
- for(i=0; i<num_poss && var_num == NOTTHERE; i++)
- {
- if(possible[i].var_mnemonic_len > CDFLIST_MAX_VAR_LENGTH)
- size = CDFLIST_MAX_VAR_LENGTH;
- else
- size = possible[i].var_mnemonic_len;
- if(strncmp(possible[i].var_mnemonic, mnemonic, size) == 0) var_num = i;
- }
- return(var_num);
- }
-
- long int get_1char(prompt)
- char prompt[];
- {
- long int resp;
- #if defined (vms)
- printf(prompt);
- resp = getchar();
- fflush(stdin);
- printf("\n");
- #else
- #if defined (ultrix)
- wprintw(stdscr, "%s",prompt);
- wrefresh(stdscr);
- fflush(stdin);
- resp = getchar();
- fflush(stdin);
- wrefresh(stdscr);
- #else
- #if defined(unix) | defined(__MSDOS__)
- wprintw(stdscr, "%s",prompt);
- wrefresh(stdscr);
- resp = getchar();
- fflush(stdin);
- #endif
- #endif
- #endif
-
- return(resp);
- }
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- static struct CDF_struct CDF;
- static struct GLOBAL_struct screen;
- struct variable_struct *variables;
- struct variable_struct *select;
- struct vid_struct *SELECT_display;
- struct vid_struct *VAR_display;
- union mixed *data_values;
- CDFstatus rcode;
- long int i;
- int var_rows;
- int var_columns;
- long int num_select;
- long int num_filter;
- int CDF_is_OPEN = FALSE;
- static char open_mes[] = "Opening CDF...";
- /* static char open_error[] = "CDFLIST_open: Error opening or Reading CDF";*/
- static char novar_mes[] = "No variables selected for listing";
- static char MULT_mes[] =
- "Must use default min/max values (EPOCH OK) for this CDF when creating new CDF";
- long int mult_flag;
- FILE *fptr;
- long int field_num;
- long int exit_code;
- long int tcode;
- long int num = 8;
- long int cdf_input = MANUAL;
- #if defined(unix) || defined(__MSDOS__)
- char *getenv();
- char *s;
- #endif
- char temp[CDF_PATHNAME_LEN];
- char help_file_name[80];
-
- QOP *qop;
- static char *validQuals[] = { NULL };
-
- for (i=0; i < CDF_NAME_LENGTH; i++) CDF.CDF_name[i] = '\0';
-
- qop = Qop (argc, argv, validQuals, NULL);
- if (qop == NULL) ExitBAD;
- switch (qop->Nparms) {
- case 0:
- strcpy(CDF.CDF_name, default_name);
- break;
- case 1:
- cdf_input = AUTO;
- strcpy(CDF.CDF_name, qop->parms[0]);
- strcpy(temp, qop->parms[0]);
- strcat(temp,".cdf");
- if(!IsReg(temp))cdf_input = DIRECTORY;
- break;
- default:
- printf ("Too many parameters.\n");
- ExitBAD;
- }
- #if defined(unix)
- s = getenv("CDF_HELP");
- if(s)
- {
- strcpy(help_file_name, s);
- strcat(help_file_name, "/cdflist.hlp");
- }
- else
- strcpy(help_file_name, "../help/cdflist.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- #endif
- #ifdef vms
- strcpy(help_file_name,"CDF$HELP:cdflist.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- #endif
- #if defined(__MSDOS__)
- s = getenv("CDF_HELP");
- if(s)
- {
- strcpy(help_file_name, s);
- strcat(help_file_name, "\\cdflist.hlp");
- }
- else
- strcpy(help_file_name, ".\\cdflist.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- if(HELP_ptr == NULL)
- {
- strcpy(help_file_name,"c:\\cdf22\\help\\cdflist.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- }
- #endif
-
-
- variables = NULL;
- select = NULL;
- VAR_display = NULL;
- SELECT_display = NULL;
- data_values = NULL;
-
- field_num = CDF_FIELD;
- CDF.file_name[0] = '\0';
- CDF.output = TERMIN;
- num_select = 0;
- SO.EPOCH_format = EPOCHFORM_DEF;
- SO.EPOCH_output_len[0] = 25;
- SO.EPOCH_output_len[1] = 17;
-
- init_var_display(init_display, num);
- CDFLIST_open_screen(&screen);
-
- while(field_num != EXIT)
- {
- switch (field_num)
- {
- case CDF_FIELD:
- CDFLIST_put_selection(screen.CDF_vid, CDF_display,
- CDFNAME_ELEMENT_NUM-1, CDF.CDF_name, CDF_NAME_LENGTH-COL_OFFSET,
- REVERSE);
- if(cdf_input != AUTO)
- tcode = CDFLIST_CDF_name(&screen, &CDF, &field_num, &cdf_input);
- else
- {
- field_num = OUT_FIELD;
- tcode = CONTINUE;
- }
- if(tcode != QUIT && field_num != EXIT && strlen(CDF.CDF_name) > 0)
- {
- if(CDF_is_OPEN)
- {
- free(variables);
- free(select);
- free(VAR_display);
- free(SELECT_display);
- free(data_values);
- if (CDF.num_attrs > 0) free(CDF.attr);
- rcode=CDFLIST_close(&CDF);
- }
- CDFLIST_put_message(screen.MES_vid, open_mes, NOBELL, BLINK,
- NOPAUSE);
- rcode = CDFLIST_open(&CDF, &variables, &select, &VAR_display,
- &SELECT_display, &data_values);
- cdf_input = MANUAL;
- if(rcode < CDF_OK) /* V1.1 */
- {
- exit_code = print_error(&screen, rcode);
- /* CDFLIST_put_message(screen.MES_vid, open_error, RINGBELL,
- NORMAL, PAUSE);*/
- if(exit_code == NOCONTINUE)field_num = CDF_FIELD;
- CDF_is_OPEN = FALSE;
- }
- else
- {
- CDF_is_OPEN = TRUE;
- num_select = 0;
- CDFLIST_var_menus(&screen, &CDF, &var_rows, &var_columns);
- CDFLIST_CDF_info(&screen, &CDF, CDF_display, OUT_display);
- CDFLIST_clear_row(screen.VAR_vid, init_display, 4,
- VAR_NUM_ELEMENTS, VAR_COLUMNS-COL_OFFSET);
- CDFLIST_clear_row(screen.MES_vid, MES_display, 1, 1,
- MES_COLUMNS-COL_OFFSET);
- init_var_display(VAR_display, CDF.num_vars);
- load_vid(screen.VAR_vid, VAR_display, 0,
- VAR_NUM_ELEMENTS, VAR_label);
- }
- }
- break;
- case OUT_FIELD:
- CDFLIST_output(&screen, &CDF, &fptr, &field_num);
- CDFLIST_clear_row(screen.MES_vid, MES_display, 1, 1,
- MES_COLUMNS-COL_OFFSET);
- break;
- case VAR_FIELD:
- CDFLIST_select_VAR(&screen, var_rows, var_columns, VAR_display,
- SELECT_display, variables, CDF.num_vars, select,
- &num_select, &field_num);
- break;
- case HELP_FIELD:
- CDFLIST_help(&screen);
- CDFLIST_field_menu(&screen, &field_num);
- case LIST_DATA:
- if(num_select == 0)
- CDFLIST_put_message(screen.MES_vid, novar_mes, RINGBELL, NORMAL,
- NOPAUSE);
- else
- {
- num_filter = num_select;
- /*
- if output is to a CDF add the independent variables that were not selected
- to the selected ones.
- */
- if(CDF.output == CDFOUT)
- {
- CDFLIST_check_filters(select, num_select,
- select, CDF.num_vars, &mult_flag);
- if(mult_flag)CDFLIST_put_message(screen.MES_vid, MULT_mes,
- RINGBELL, NORMAL, PAUSE);
- CDFLIST_add_independent(select, &num_select,
- variables, CDF.num_vars);
- }
- CDFLIST_list_data(&screen, &CDF, select, num_select,
- num_filter, data_values, fptr);
- }
- CDFLIST_field_menu(&screen, &field_num);
- }
- }
- if(HELP_ptr != NULL)fclose(HELP_ptr);
- if(CDF.output == FILEOUT || CDF.output == TERMFILE)fclose(fptr);
- if(CDF_is_OPEN)rcode=CDFLIST_close(&CDF);
- CDFLIST_close_screen(&screen);
- Exit;
- }
- void header(mnemonic, len, data_type, string_size, header_name)
- char *mnemonic;
- long int len;
- long int data_type;
- long int string_size;
- char header_name[];
- {
- long int i;
- long int num_blanks;
- long int field_size;
- if(data_type == CDF_EPOCH)
- field_size = SO.EPOCH_output_len[SO.EPOCH_format-1];
- else if(data_type == CDF_CHAR || data_type == CDF_UCHAR )
- {
- if(string_size > len)
- field_size = string_size;
- else
- field_size = len;
- }
- else
- field_size = 13;
- if(len <= field_size)
- {
- num_blanks = (field_size - len) / 2;
- for(i=0; i < num_blanks; i++)
- header_name[i] = ' ';
- for(i=0; i < len; i++)
- header_name[i+num_blanks] = mnemonic[i];
- for(i=num_blanks+len; i < field_size; i++)
- header_name[i] = ' ';
- }
- else
- strncpy(header_name, mnemonic, field_size);
- header_name[field_size] = '\0';
- }
- long int print_error(screen, rcode)
- struct GLOBAL_struct *screen;
- CDFstatus rcode;
- {
- long int exit_code;
- char error_mes[CDF_ERRTEXT_LEN];
- if(rcode < CDF_WARN)
- exit_code = NOCONTINUE;
- else if(rcode < CDF_OK)
- exit_code = CONTINUE;
- else if(rcode != CDF_OK)
- exit_code = CONTINUE;
- /*
- Get and print the error message
- */
- CDFerror(rcode, error_mes);
- CDFLIST_put_message(S.MES_vid, error_mes, RINGBELL, NORMAL, PAUSE);
- return(exit_code);
- }
- CDFstatus CDFLIST_open(CDF, variables, select, VAR_display, SELECT_display,
- data_values)
- struct CDF_struct *CDF;
- struct variable_struct **variables;
- struct variable_struct **select;
- struct vid_struct **VAR_display;
- struct vid_struct **SELECT_display;
- union mixed **data_values;
- {
- CDFstatus rcode;
- long int i;
- long int var_num;
- long int attr_num;
- long int dim_num;
- long int num_true;
- long int num;
- void CDFLIST_valid_minmax();
- static char truncation[] = "...";
-
- rcode = CDFopen(C.CDF_name, &C.CDF_id);
-
- if(rcode < CDF_OK)return (rcode);
- rcode = CDFdoc(C.CDF_id, &C.version, &C.release, C.text);
-
- for(i=0; i<CDF_MAX_DIMS; i++)
- C.dim_sizes[i] = FALSE;
- rcode = CDFinquire(C.CDF_id, &C.num_dims, C.dim_sizes, &C.encoding,
- &C.majority, &C.max_record_num, &C.num_vars, &C.num_attrs);
- if(rcode < CDF_OK)return(rcode);
- *variables = (struct variable_struct *)
- malloc(C.num_vars * sizeof(struct variable_struct));
- if(*variables == NULL)return(BAD_MALLOC);
-
- if(C.version == 1)
- {
- C.encoding = HOST_ENCODING;
- C.majority = COL_MAJOR;
- }
- else
- if(C.encoding != NETWORK_ENCODING) C.encoding = HOST_ENCODING;
-
- if(C.num_attrs > 0)
- {
- C.attr = (struct attr_struct *)
- malloc(C.num_attrs * sizeof(struct attr_struct));
- if(C.attr == NULL)return(BAD_MALLOC);
- for(attr_num=0; attr_num<C.num_attrs; attr_num++)
- {
- rcode = CDFattrInquire(C.CDF_id, attr_num,
- C.attr[attr_num].attr_mnemonic, &C.attr[attr_num].attr_scope,
- &C.attr[attr_num].max_entry);
- }
- }
- /*
- Set default for the "**SELECT ALL**" option in variable selection pop-up window
- */
- C.max_var_len = 14;
- for (var_num=0; var_num < C.num_vars; var_num++)
- {
- for(i=0; i<CDF_MAX_DIMS; i++)
- VN.dim_variances[i] = FALSE;
- rcode = CDFvarInquire(C.CDF_id, var_num, VN.var_mnemonic, &VN.data_type,
- &VN.num_bytes, &VN.record_variance, VN.dim_variances);
- if(rcode < CDF_OK) /* V1.1 */
- return (rcode);
- else
- {
- VN.var_num = var_num;
- VN.var_mnemonic_len = strlen(VN.var_mnemonic);
- /*
- header(VN.var_mnemonic, VN.var_mnemonic_len, VN.data_type, VN.num_bytes,
- VN.header_name); */
- if(VN.var_mnemonic_len > C.max_var_len)C.max_var_len=VN.var_mnemonic_len;
- VN.filter = FALSE;
- VN.scalar = SCALAR;
- VN.minmax_flag = NORMAL;
- num_true=0;
- for (i=0; i< C.num_dims; i++)
- {
- if(VN.dim_variances[i] != NOVARY)
- {
- dim_num=i+1;
- num_true++;
- VN.scalar = FALSE;
- }
- }
- if((num_true == 1 && !VN.record_variance) &&
- (VN.data_type != CDF_CHAR && VN.data_type != CDF_UCHAR ))
- {
- VN.dim_num = dim_num;
- VN.num_values=C.dim_sizes[dim_num-1];
- VN.bin_value = (double *) malloc(VN.num_values * sizeof(double));
- VN.char_value = (char *) malloc(VN.num_values*MINMAX_SIZE);
- if(VN.bin_value == NULL || VN.char_value == NULL)
- rcode = BAD_MALLOC;
- else
- rcode = CDFLIST_get_discrete(C.CDF_id, dim_num,
- VN.var_num, VN.data_type, VN.num_values, VN.bin_value, VN.char_value);
- }
- else
- {
- if(!VN.record_variance && num_true > 1)
- VN.dim_num = MULTIPLE;
- else
- VN.dim_num=0;
- VN.num_values=0;
- }
- if(initialfilters)
- {
- CDFLIST_valid_minmax (C.CDF_id, CDFattrNum(C.CDF_id,"VALIDMIN"), var_num,
- &VN.min, &rcode);
- if(rcode != CDF_OK)VN.minmax_flag = NOTTHERE;
- CDFLIST_valid_minmax (C.CDF_id, CDFattrNum(C.CDF_id,"VALIDMAX"), var_num,
- &VN.max, &rcode);
- if(rcode != CDF_OK)VN.minmax_flag = NOTTHERE;
- rcode = 0;
- }
- /* It is OK if these attributes aren't found */
- }
- }/*var loop*/
- /*
- Allocate rest of structures needed based upon number of variables
- */
- *select = (struct variable_struct *)
- malloc(C.num_vars * sizeof(struct variable_struct));
- if(*select == NULL)return(BAD_MALLOC);
- if(C.num_vars < 8)
- num = 8;
- else
- num = C.num_vars;
- *VAR_display = (struct vid_struct *)
- malloc(((num+1)*3) * sizeof(struct vid_struct));
- if(*VAR_display == NULL)return(BAD_MALLOC);
- /*
- allocate the space for a vid structure which contains the variables
- extra space for "SELECT ALL" option
- */
- *SELECT_display = (struct vid_struct *)
- malloc((C.num_vars+1) * sizeof(struct vid_struct));
- if(*SELECT_display == NULL)return(BAD_MALLOC);
- /*
- Load in the variables into the structure
- */
- for (i=0; i<C.num_vars+1; i++)
- {
- (*SELECT_display)[i].row = 1;
- (*SELECT_display)[i].col = 1;
- if(i == 0)
- strcpy((*SELECT_display)[i].label,"**SELECT ALL**");
- else if((*variables)[i-1].var_mnemonic_len < VARSELECT_COLUMNS)
- strcpy((*SELECT_display)[i].label,(*variables)[i-1].var_mnemonic);
- else
- {
- strncpy((*SELECT_display)[i].label,(*variables)[i-1].var_mnemonic,
- VARSELECT_COLUMNS-3);
- strcat((*SELECT_display)[i].label,truncation);
- }
- (*SELECT_display)[i].field_col = 1;
- }
- *data_values = (union mixed *)
- malloc(C.num_vars * sizeof(union mixed));
- if(*data_values == NULL)return(BAD_MALLOC);
-
- return (rcode);
- }
-
- void CDFLIST_get_data(CDF, select, num_select, record_num, indices, data_values)
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- long int record_num;
- long int indices[];
- union mixed data_values[];
-
- {
- long int i;
-
- for (i = 0; i < num_select; i++)
- {
- switch (select[i].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].r4);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].r8);
- break;
- case CDF_INT4:
- case CDF_UINT4:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].i4);
- break;
- case CDF_INT2:
- case CDF_UINT2:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].i2);
- break;
- case CDF_BYTE:
- case CDF_INT1:
- case CDF_UINT1:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].byte);
- break;
- case CDF_CHAR:
- case CDF_UCHAR:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, data_values[i].string);
- data_values[i].string[select[i].num_bytes] = '\0';
- }
- }
- }
- CDFstatus CDFLIST_alloc_STRING(select, num_select, data_values)
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- {
- long int i;
-
- for (i = 0; i < num_select; i++)
- {
- if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
- /*
- If this is a STRING variable allocate a enough space in the union array
- to hold this variable
- */
- {
- data_values[i].string = (char *) malloc(select[i].num_bytes+1);
- if(data_values[i].string == NULL)return(BAD_MALLOC);
- }
- }
- return 0;
- }
- void CDFLIST_free_STRING(select, num_select, data_values)
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- {
- long int i;
- for(i=0; i<num_select; i++)
- {
- if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
- free(data_values[i].string);
- }
- }
- long int CDFLIST_create_new_CDF(screen, CDF, select, num_select, new_CDF)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- struct CDF_struct *new_CDF;
- {
- long int i;
- long int attr_num;
- long int entry_num;
- long int exit_code;
- CDFstatus rcode;
- long int data_type;
- long int num_elements;
- long int out_attr_num;
-
- /*
- Create the New CDF
- */
- rcode = CDFcreate(NC.CDF_name, NC.num_dims, NC.dim_sizes,
- NC.encoding, NC.majority, &NC.CDF_id);
- if(rcode != CDF_OK)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- /*
- Create the variables
- */
- for(i=0; i<num_select; i++)
- {
- rcode = CDFvarCreate(NC.CDF_id, select[i].var_mnemonic,
- select[i].data_type, select[i].num_bytes,
- select[i].record_variance, select[i].dim_variances,
- &select[i].out_var_num);
- if(rcode != CDF_OK)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- /*
- Create the attributes
- */
- for (attr_num=0; attr_num<C.num_attrs; attr_num++)
- {
- rcode = CDFattrCreate(NC.CDF_id, C.attr[attr_num].attr_mnemonic,
- C.attr[attr_num].attr_scope, &out_attr_num);
- if(rcode != CDF_OK)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- /*
- Insert the global attributes
- */
- for (attr_num=0; attr_num<C.num_attrs; attr_num++)
- {
- if(C.attr[attr_num].attr_scope == GLOBAL_SCOPE ||
- C.attr[attr_num].attr_scope == GLOBAL_SCOPE_ASSUMED)
- {
- for(entry_num = 0; entry_num <= C.attr[attr_num].max_entry; entry_num++)
- {
- rcode = CDFattrEntryInquire(C.CDF_id, attr_num, entry_num,
- &data_type, &num_elements);
- if(rcode >= CDF_OK)
- {
- rcode = put_attr_value(C.CDF_id, attr_num, entry_num,
- entry_num, NC.CDF_id, data_type, num_elements);
- if(rcode != CDF_OK)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- else if(rcode != NO_SUCH_ENTRY)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- }
- }
- /*
- Insert the variable attributes
- */
- for (attr_num=0; attr_num<C.num_attrs; attr_num++)
- {
- for(i = 0; i < num_select; i++)
- {
- if(C.attr[attr_num].attr_scope == VARIABLE_SCOPE ||
- C.attr[attr_num].attr_scope == VARIABLE_SCOPE_ASSUMED)
- {
- rcode = CDFattrEntryInquire(C.CDF_id, attr_num, select[i].var_num,
- &data_type, &num_elements);
- if(rcode >= CDF_OK)
- {
- rcode = put_attr_value(C.CDF_id, attr_num, select[i].var_num, i,
- NC.CDF_id, data_type, num_elements);
- if(rcode != CDF_OK)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- else if(rcode != NO_SUCH_ENTRY)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)return (exit_code);
- }
- }
- }
- }
- return (CDF_OK);
- }
-
- CDFstatus put_attr_value(in_CDF_id, attr_num, entry_num, out_entry_num,
- out_CDF_id, data_type, num_elements) /* V1.3 */
- CDFid in_CDF_id;
- long int attr_num;
- long int entry_num;
- long int out_entry_num; /* V1.3 */
- CDFid out_CDF_id;
- long int data_type;
- long int num_elements;
- {
- void *attr_values;
- CDFstatus rcode;
-
- switch(data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- attr_values =
- (void *) malloc(num_elements * sizeof(float));
- if(attr_values == NULL)return(BAD_MALLOC); /* V1.5 */
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- break;
- case CDF_CHAR:
- case CDF_UCHAR:
- attr_values = (void *) malloc(num_elements+1); /* V1.5 */
- if(attr_values == NULL)return(BAD_MALLOC);
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- attr_values =
- (void *) malloc(num_elements * sizeof(double)); /* V1.5 */
- if(attr_values == NULL)return(BAD_MALLOC);
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- break;
- case CDF_INT4:
- case CDF_UINT4:
- attr_values =
- (void *) malloc(num_elements * sizeof(long int)); /* V1.5 */
- if(attr_values == NULL)return(BAD_MALLOC);
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- break;
- case CDF_INT2:
- case CDF_UINT2:
- attr_values =
- (void *) malloc(num_elements * sizeof(short int)); /* V1.5 */
- if(attr_values == NULL)return(BAD_MALLOC);
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- break;
- case CDF_BYTE:
- case CDF_INT1:
- case CDF_UINT1:
- attr_values = (void *) malloc(num_elements); /* V1.5 */
- if(attr_values == NULL)return(BAD_MALLOC);
- rcode = CDFattrGet(in_CDF_id, attr_num, entry_num, attr_values);
- if(rcode >= CDF_OK) /* V1.1 */
- {
- rcode = CDFattrPut(out_CDF_id, attr_num, out_entry_num,
- data_type, num_elements, attr_values); /* V1.3 */
- }
- }/*end switch*/
- free (attr_values);
- return (rcode);
- }
- void CDFLIST_new_CDF_info(CDF, select, num_select, new_CDF)
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- struct CDF_struct *new_CDF;
- {
- long int i,j, ii;
- long int temp_dim_size;
- long int vars_per_dim[10];
- long int num_pass;
- long int num_vars;
- long int dim_num;
-
- strcpy(NC.CDF_name,C.file_name);
- /*
- new number of dimensions = old number of dimensions
- */
- NC.num_dims = C.num_dims;
- /*
- initialize new dim sizes to old dim sizes and also set up the
- input start and stop indices array to complete dimensions
- */
- for (i=0; i<NC.num_dims; i++)
- NC.dim_sizes[i] = C.dim_sizes[i];
-
- NC.majority = C.majority;
- NC.encoding = C.encoding;
- /*
- Go thru all dimensions to calculate new dimension sizes
- */
- for(dim_num=1; dim_num <= NC.num_dims; dim_num++)
- {
- num_vars = 0;
- /*
- Look for variables that vary with respect to the current dimension
- */
- for(j=0; j<num_select; j++)
- {
- if(select[j].dim_num == dim_num)
- {
- vars_per_dim[num_vars] = j;
- num_vars++;
- }
- }
- /*
- Make sure there were variables selected for this dimension
- */
- if(num_vars > 0)
- {
- /*
- Loop thru all values in this dimension, all variables in this
- dimension must be checked
- */
- temp_dim_size = 0;
- for (j = 0; j < NC.dim_sizes[dim_num-1]; j++)
- {
- num_pass=0;
- for (ii = 0; ii <num_vars; ii++)
- {
- i = vars_per_dim[ii];
- if(!select[i].filter)
- num_pass++;
- else
- {
- if(select[i].bin_value[j] >= select[i].filter_min &&
- select[i].bin_value[j] <= select[i].filter_max)
- num_pass++;
- }
- }
- /*
- if the number of variables that passed the test is equal to the number of
- variables selected for this dimension bump the dim size by one
- */
- if(num_pass == num_vars)temp_dim_size++;
- }/*loop thru values per dim*/
- /*
- Load in the new size for this dimension
- */
- NC.dim_sizes[dim_num-1] = temp_dim_size;
- }/*num_vars>0*/
- }/*dimension numbers*/
- }
- void CDFLIST_list_data(screen, CDF, select, num_select, num_filter,
- data_values, fptr)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- long int num_filter;
- union mixed *data_values;
- FILE *fptr;
- {
- struct CDF_struct new_CDF;
- long int line_cnt;
- long int line_width;
- long int num_lines_page;
- long int cont, cont_file, resp;
- static char file_mes[] = "Output to file ";
- static char tp[] = " taking place...";
- static char cdf_mes[] = "Output to CDF ";
- static char file_done_mes[] = "File Processing complete ";
- #if defined(__MSDOS__)
- static char scan_mes[] = "Scanning for selected data. Hit <Q> to interrupt...";
- #else
- static char scan_mes[] = "Scanning for selected data...";
- #endif
- static char nodata_mes[] = "No data found in the specified range";
- #ifdef vms
- static char cont_prompt[] =
- "Hit <CR> to continue listing, any other key + <CR> to end ";
- static char contfile_prompt[] =
- "Would you like to continue the output to your file (Y/N)";
- #endif
- #if defined(unix) | defined(__MSDOS__)
- static char cont_prompt[] =
- "Hit <CR> to continue listing, any other key to end ";
- static char contfile_prompt[] =
- "\nWould you like to continue the output to your file (Y/N)";
- static char trunc_mes[] =
- "Terminal Output will be truncated at variables because of line width";
- #endif
- static char end_prompt[] =
- "END of LISTING, Hit <CR> to continue ";
- char mes[80];
- long int valid;
- long int first;
- long int first_valid;
- long int data_found_in_record;
- long int data_found;
- long int record_pass;
- long int i;
- double fudge_down, fudge_up;
- long int record_num, out_record_num;
- long int dim_num;
- long int x[10],ox[10];
- long int copy_complete;
- long int change_output;
- long int max_terminal;
- long int rcode;
- long int exit_code;
- char num[4];
- char ch;
- if(C.output != CDFOUT)
- {
- for(i=0; i<num_select; i++)
- {
- header(select[i].var_mnemonic, select[i].var_mnemonic_len,
- select[i].data_type, select[i].num_bytes,
- select[i].header_name);
- }
- }
- /*
- if output to a file is specified create a file header
- with the variable information for the listing
- */
- if(C.output == FILEOUT || C.output == TERMFILE)
- CDFLIST_file_header(CDF, select, num_select, fptr);
- /*
- on UNIX we will only be able to write out 132 chars to screen
- */
- max_terminal = NOTTHERE;
- /*
- Calculate number of lines per page if listing output to terminal
- */
- num_lines_page = 22;
- if(C.output == TERMFILE || C.output == TERMIN)
- {
- line_width = 0;
- for(i=0; i < num_select; i++)
- {
- if(select[i].data_type == CDF_EPOCH)
- line_width = line_width + SO.EPOCH_output_len[SO.EPOCH_format-1];
- else if(select[i].data_type == CDF_CHAR ||
- select[i].data_type == CDF_UCHAR)
- line_width = line_width + select[i].num_bytes;
- else
- line_width = line_width + 14;
- #if defined (unix) | defined (__MSDOS__)
- if((line_width > 132) && (max_terminal == NOTTHERE))
- {
- max_terminal = i + 1;
- sprintf(num, "%2d", max_terminal);
- strncpy(trunc_mes+37, num, 2);
- CDFLIST_put_message(S.MES_vid, trunc_mes, RINGBELL, NORMAL, PAUSE);
- }
- #endif
- }
- if(line_width > 78)
- num_lines_page = 10;
- #if defined (unix) | defined(__MSDOS__)
- else if(C.output == TERMFILE)
- num_lines_page = 21;
- #endif
- }
- /*
- If line_width never got to 132 or VMS, max_terminal and num_select
- will be the same
- */
- if (max_terminal == NOTTHERE)max_terminal = num_select;
-
- /*
- Fudge factor to insure filtering reliability
- */
- fudge_down = .999999; fudge_up = 1.000001;
- for (i=0; i<num_select; i++)
- {
- if(select[i].filter)
- {
- if(select[i].data_type != CDF_REAL8 && select[i].data_type != CDF_DOUBLE &&
- select[i].data_type != CDF_EPOCH)
- /* V1.6 */
- {
- if(select[i].min > 0)
- select[i].filter_min = fudge_down*select[i].min;
- else
- select[i].filter_min = fudge_up*select[i].min;
-
- if(select[i].max > 0)
- select[i].filter_max = fudge_up*select[i].max;
- else
- select[i].filter_max = fudge_down*select[i].max;
- }
- else
- {
- select[i].filter_min = select[i].min;
- select[i].filter_max = select[i].max;
- }
-
- }
- }
-
- mes[0] = '\0';
- /*
- Tell the USER what's going on
- */
- if(C.output == TERMFILE || C.output == TERMIN)
- CDFLIST_put_message(S.MES_vid, scan_mes, NOBELL, BLINK, NOPAUSE);
- else if(C.output == FILEOUT)
- {
- strcat(mes, file_mes); strcat(mes, C.file_name); strcat(mes, tp);
- CDFLIST_put_message(S.MES_vid, mes, NOBELL, BLINK, NOPAUSE);
- }
- else
- {
- strcat(mes, cdf_mes); strcat(mes, C.file_name); strcat(mes, tp);
- CDFLIST_put_message(S.MES_vid, mes, NOBELL, BLINK, NOPAUSE);
- }
- /*
- Generate information about output as though we are always creating
- a new CDF, this will speed processing time
- */
- CDFLIST_new_CDF_info(CDF, select, num_filter, &new_CDF);
- if(C.output == CDFOUT)
- {
- /*
- Create the NEW CDF
- */
- rcode = CDFLIST_create_new_CDF(screen, CDF, select, num_select, &new_CDF);
- if(rcode == NOCONTINUE)return;
- out_record_num = -1;
- }
- first = TRUE; first_valid = TRUE; data_found = FALSE;
- line_cnt = 0; cont = CONTINUE;
- change_output = FALSE;
- fflush(stdin);
-
- rcode = CDFLIST_alloc_STRING(select, num_select, data_values);
- if(rcode != 0)
- {
- exit_code = print_error(screen, rcode);
- if(exit_code == NOCONTINUE)ExitBAD;
- }
- /* standby for liftoff */
-
- for(record_num=0; record_num <= C.max_record_num && cont==CONTINUE; ++record_num)
- {
- for(dim_num = 0; dim_num < C.num_dims; ++dim_num)
- {
- x[dim_num] = 0;
- ox[dim_num] = 0;
- }
- data_found_in_record = FALSE;
- copy_complete = FALSE;
- first = TRUE;
- while (!copy_complete && cont == CONTINUE)
- {
- /*
- Get the data for the variables
- */
- CDFLIST_get_data(CDF, select, num_select,
- record_num, x, data_values);
- if(first)
- {
- CDFLIST_filter(select, num_filter, data_values, SCALAR,
- &record_pass);
- first = FALSE;
- }
- if(record_pass)
- {
-
- /*
- See if the data falls within the range of the specified filters
- */
- CDFLIST_filter(select, num_filter, data_values, NORMAL, &valid);
- if(valid)
- {
- if(C.output == CDFOUT)
- {
- if(!data_found_in_record)out_record_num++;
- data_found_in_record = TRUE;
- CDFLIST_put_CDF(&new_CDF, out_record_num, ox,
- select, num_select, data_values);
- data_found = TRUE;
- }
- else
- {
- /*
- Data passes all filters, if this is the first time then save off the
- SMG so data may be listed to the screen
- */
- #ifdef vms
- if((first_valid) &&
- (C.output == TERMIN || C.output == TERMFILE))
- CDFLIST_save_screen(screen);
- #endif
- data_found = TRUE;
- line_cnt++;
- /*
- Print a HEADER to the listing
- */
- #if defined(unix) | defined(__MSDOS__)
- if(line_cnt == 1 && C.output != FILEOUT)
- unpaste_virtual_display_only(stdscr);
- #endif
- if(line_cnt == 1)
- CDFLIST_print_header(select, num_select, max_terminal,
- C.output, fptr, first_valid);
- first_valid = FALSE;
- CDFLIST_print_data(select, data_values, num_select,
- max_terminal, C.output, fptr);
- if((line_cnt == num_lines_page) &&
- (C.output == TERMIN || C.output == TERMFILE))
- {
- /*
- End of a full page, see if the USER wishes to continue (TERMINAL output)
- */
-
- cont = get_1char(cont_prompt);
- if(cont != CONTINUE && C.output == TERMFILE)
- {
- /*
- USER wishes to stop TERMINAL output, if he is using TERMINAL/FILE output
- see if he wishes to continue his output to his FILE
- */
- resp = FALSE;
- while(!resp)
- {
- cont_file = get_1char(contfile_prompt);
- if(cont_file == YES || cont_file == yes)
- {
- C.output = FILEOUT;
- #if defined(unix) | defined(__MSDOS__)
- unpaste_virtual_display_only(stdscr);
- CDFLIST_draw_main_screen(screen);
- #endif
- #ifdef vms
- CDFLIST_restore_screen(screen);
- #endif
- mes[0] = '\0';
- strcat(mes, file_mes); strcat(mes, C.file_name);
- strcat(mes, tp);
- CDFLIST_put_message(S.MES_vid, mes, NOBELL,
- BLINK, NOPAUSE);
- cont = CONTINUE; resp = OK_RESP;
- change_output = TRUE;
- }
- else if(cont_file == NO || cont_file == no)
- resp = OK_RESP;
- }
- }
- line_cnt = 0;
- } /* line_cnt */
- }
- /*
- Check output indices to see if all output indices have been filled
- */
- next_indices(ox, new_CDF.num_dims, new_CDF.dim_sizes,
- ©_complete);
- } /* valid point */
- /*
- Generate next set indices
- */
- if(cont == CONTINUE && !copy_complete)
- next_indices(x, C.num_dims, C.dim_sizes, ©_complete);
-
- }/* !copy_comple*/
- else
- copy_complete = TRUE;
-
-
- /*
- Look for user trying to break the search - aw3
- */
-
- #if defined(__MSDOS__)
- if (kbhit()) /* abort disp if keypressed */
- {
- if ( (ch = getch()) == 0)
- ch = 0x80 | getch();
- if ((ch == 'Q') || (ch == 'q'))
- {
- copy_complete = TRUE;
- cont = NOCONTINUE;
- }
- }
- #endif
- }/*record_passes*/
- }/*record_num*/
-
- CDFLIST_free_STRING(select, num_select, data_values);
-
- if((C.output == TERMIN || C.output == TERMFILE) &&
- (cont == CONTINUE && data_found))
- cont = get_1char(end_prompt);
- else if (C.output == CDFOUT)
- rcode=CDFLIST_close(&new_CDF);
- if((data_found) &&
- (C.output == TERMIN || C.output == TERMFILE))
- {
- /*
- Restore the SMG SCREEN so additional listings may be produced
- */
- #if defined(unix) | defined(__MSDOS__)
- unpaste_virtual_display_only(stdscr);
- CDFLIST_draw_main_screen(screen);
- #endif
- #ifdef vms
- CDFLIST_restore_screen(screen);
- #endif
- CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- }
- else if(!data_found)
- /*
- These was no data found in the specified ranges
- */
- CDFLIST_put_message(S.MES_vid, nodata_mes, RINGBELL, NORMAL, NOPAUSE);
- else
- CDFLIST_put_message(S.MES_vid, file_done_mes, NOBELL, NORMAL, NOPAUSE);
- first_valid = TRUE;
- first = TRUE;
- if(change_output)C.output = TERMFILE;
- }
- void next_indices(x, num_dims, dim_sizes, copy_complete)
- long int x[];
- long int num_dims;
- long int dim_sizes[];
- long int *copy_complete;
- {
- long int cp;
- long int valid_perm;
- long int dim_num;
- cp = *copy_complete;
- if(num_dims == 0)
- cp = TRUE;
- else
- {
- valid_perm = FALSE;
- dim_num = 1;
- while (!valid_perm && !cp)
- {
- if (x[dim_num-1] < (dim_sizes[dim_num-1] - 1))
- {
- x[dim_num-1] = x[dim_num-1] + 1;
- valid_perm = TRUE;
- }
- else
- {
- if (dim_num < num_dims)
- {
- x[dim_num-1] = 0;
- dim_num = dim_num + 1;
- }
- else
- cp = TRUE;
- }
- }/*valid_perm*/
- }
- *copy_complete = cp;
- }
- void CDFLIST_check_filters(select, num_select, variables, num_vars, mult_flag)
- struct variable_struct select[];
- long int num_select;
- struct variable_struct variables[];
- long int num_vars;
- long int *mult_flag;
- {
- long int i,j;
- long int found;
- *mult_flag = FALSE;
- for (j=0; j<num_select; j++)
- {
- if(select[j].dim_num == MULTIPLE)
- {
- *mult_flag = TRUE;
- found = FALSE;
- for (i=0; i<num_vars && !found; i++)
- {
- if(strcmp(select[j].var_mnemonic,variables[i].var_mnemonic)==0)
- select[j].filter = FALSE;
- found = TRUE;
- }
- }
- }
- for (j=0; j<num_select; j++)
- {
- if(select[j].filter && select[j].record_variance == VARY &&
- !select[j].scalar)select[j].filter = FALSE;
- }
- }
- void CDFLIST_add_independent(select, num_select, variables, num_vars)
- struct variable_struct select[];
- long int *num_select;
- struct variable_struct variables[];
- long int num_vars;
- {
- long int i,j, ii;
- long int ns;
- long int found;
- ns = *num_select;
- for (i=0; i<num_vars; i++)
- {
- if(!variables[i].record_variance)
- {
- found = FALSE;
- for (j=0; j<ns; j++)
- {
- if(strcmp(select[j].var_mnemonic, variables[i].var_mnemonic)==0)
- found = TRUE;
- }
- if(!found)
- {
- strcpy(select[*num_select].var_mnemonic,
- variables[i].var_mnemonic);
- select[*num_select].var_num = variables[i].var_num;
- select[*num_select].record_variance =
- variables[i].record_variance;
- for (ii=0; ii< 10; ii++)
- select[*num_select].dim_variances[ii] =
- variables[i].dim_variances[ii];
- select[*num_select].num_bytes = variables[i].num_bytes;
- select[*num_select].num_values= variables[i].num_values;
- select[*num_select].dim_num = variables[i].dim_num;
- select[*num_select].bin_value = variables[i].bin_value;
- select[*num_select].min = variables[i].min;
- select[*num_select].max = variables[i].max;
- select[*num_select].data_type = variables[i].data_type;
- select[*num_select].filter = FALSE;
- *num_select = *num_select + 1;
- }
- }/*RV FALSE*/
- }/*var loop*/
- }
- void CDFLIST_select_VAR(screen, num_rows, num_cols, display,
- SELECT_display, possible, num_poss, select, num_select, in_field_num)
- struct GLOBAL_struct *screen;
- int num_rows;
- int num_cols;
- struct vid_struct display[];
- struct vid_struct *SELECT_display;
- struct variable_struct possible[];
- long int num_poss;
- struct variable_struct *select;
- long int *num_select;
- long int *in_field_num;
- {
- struct vid_struct *DIS_display;
- long int i, n;
- double min_max;
- long int var_num, val_num, select_num;
- int row, col;
- long int scroll;
- int tcode;
- long int col_field, col_paste, dis_rows;
- long int first_blank;
- int field_num;
- int last_error;
- int len;
- long int exit_code;
- char mes[80];
- char row_data[80];
- char value[EPOCH_WIDTH];
- char mnemonic[CDFLIST_MAX_VAR_LENGTH+1];
- char temp[CDFLIST_MAX_VAR_LENGTH+1];
- char key_line1[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- char key_line2[KEY_COLUMNS-COL_OFFSET+1]; /* V1.5 */
- static int scolumns[3] = { 6, 26, 52 };
- int error;
- long int select_all, start, end;
- long int erase_mode;
- long int value_entered;
- long int start_page; /*jtl*/
- long int ok;
- Boolean echeck;
- int bump;
- int redraw;
- double dummy;
- CDFstatus rcode;
- static char dup_mes[] = " has already been selected";
- static char min_max_error[] = "Error detected in MIN_MAX field";
- static char select_var_mes[] =
- "Press CTL-P to view valid variables and select from pop-up menu";
- static char select_data_mes[] =
- "Enter MIN/MAX value or press CTL-P to select discrete values from pop-up menu";
- static char no_discrete_mes[] =
- "Current Variable does not contain only discrete values, manual input required";
- static char string_mes[] =
- "Variable not available for filtering, please use another variable if possible";
- static char min_gt_max[] =
- "Minimum value greater than Maximum value";
- static char EPOCH_format[] =
- "DD-MMM-YYYY HH:MM:SS.MSC";
- static char EPOCH_error_mes[] =
- "Error detected reading EPOCH";
-
- var_num = 1;
- tcode = CONTINUE;
- last_error = FALSE;
- col_field = 1;
- redraw = TRUE;
- row = 2;
- read_display(S.VAR_vid, row, row_data);
- get_field(row_data, 1, 3, mnemonic, &first_blank, &value_entered);
- sscanf(row_data, "%3ld",&select_num);
- start_page = select_num;
- while(tcode != KB_CTRL_F)
- {
- key_line1[0] ='\0'; key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1, UP);strcat(key_line1, NEXT);
- strcat(key_line1, DEL);;
- /* V1.5 */
- strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);strcat(key_line2,BACK);
- strcat(key_line2, HLP);
- CDFLIST_load_keydef(S.KEY_vid, key_line1, key_line2);
- /*
- Calculate which position to be positioned to
- */
- field_num = select_num * 3 + col_field;
- col = scolumns[col_field-1];
- if(redraw)
- {
- redraw = FALSE;
- erase_mode = ERASE;
- begin_display_update(S.VAR_vid);
- for(i=0; i<3; i++)
- {
- put_chars(S.VAR_vid, display[i].label, 8,
- display[i].row, display[i].col, erase_mode, NORMAL);
- erase_mode = NOERASE;
- }
- #if defined(vms)
- end_display_update(S.VAR_vid);
- #else
- end_display_update_nobox(S.VAR_vid);
- #endif
- }
- if(col_field == 1)
- {
- /*
- Select a variable
- */
- if(!last_error)
- CDFLIST_put_message(S.MES_vid, select_var_mes, NOBELL, NORMAL, NOPAUSE);
- last_error = FALSE;
- set_cursor_abs(S.VAR_vid, row, col);
- /*
- See if the USER wishes to select a variable
- */
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- read_input(S.VAR_vid, &tcode);
- #endif
- }
- else
- { /* min or max */
- /*
- Minimum or Maximum range input
- first Copy Mnemonic
- */
- read_display(S.VAR_vid, row, row_data);
- get_field(row_data, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
- &first_blank, &value_entered);
- error = TRUE;
- while (error)
- {
- error = FALSE;
- set_cursor_abs(S.VAR_vid, row, col);
- read_display(S.VAR_vid, row, row_data);
- /*
- Copy Mnemonic
- */
- get_field(row_data, 6, CDFLIST_MAX_VAR_LENGTH, mnemonic,
- &first_blank, &value_entered);
- /*
- Copy Minimum or Maximum value so it may be edited
- */
- var_num = get_var_num(possible, mnemonic, num_poss);
- if(var_num == NOTTHERE)
- len = MINMAX_SIZE;
- else if(possible[var_num].data_type != CDF_EPOCH)
- len = MINMAX_SIZE;
- else
- {
- len = EPOCH_WIDTH;
- put_chars(S.VAR_vid, EPOCH_format, EPOCH_WIDTH,
- display[col_field-1].row, display[col_field-1].col,
- NOERASE, NORMAL);
- redraw = TRUE;
- }
- if(!last_error)
- CDFLIST_put_message(S.MES_vid, select_data_mes, NOBELL,
- NORMAL, NOPAUSE);
- get_field(row_data, col, len, value,
- &first_blank, &value_entered);
- input_field(S.VAR_vid, value,
- row, col, len-1, &tcode);
- #if !defined(__MSDOS__)
- change_rendition(S.VAR_vid,row,col,1,len,NORMAL);
- #endif
- if(possible[var_num].data_type != CDF_EPOCH)
- {
- n = sscanf(value,"%lf",&min_max);
- if(n == MIN_MAX_ERROR)
- {
- CDFLIST_put_message(S.MES_vid, min_max_error, RINGBELL,
- BLINK, PAUSE);
- error = TRUE;
- }
- else
- {
- strcpy(display[field_num-1].label, value);
- if(error)
- CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS);
- }
- } /* normal min or max */
- else
- { /* EPOCH min or MAX */
- echeck = check_epoch(value, &dummy);
- if(!echeck)
- {
- CDFLIST_put_message(S.MES_vid, EPOCH_error_mes, RINGBELL,
- BLINK, PAUSE);
- error = TRUE;
- }
- else
- {
- CDFLIST_put_select_row(S.VAR_vid, display, row, field_num-1,
- value, EPOCH_WIDTH, NORMAL);
- strcpy(display[field_num-1].label, value);
- if(error)
- CDFLIST_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS);
- }
- } /* end EPOCH min or max */
- } /* read in value */
- }/* min or max end */
- switch (tcode)
- {
- case KB_DOWNARROW:
- row++; select_num++;
- if(select_num > num_poss)select_num = 1;
- if(row > 9)
- {
- if(num_poss > 8)
- {
- row = 9;
- start_page++;
- if(start_page > num_poss)start_page = 1;
- load_vars(S.VAR_vid, display, start_page, num_poss);
- }
- else
- {
- row = 2;
- select_num = 1;
- start_page = 1;
- }
- }
- break;
- case KB_UPARROW:
- row--; select_num--;
- if(select_num < 1)select_num = num_poss;
- if(row < 2)
- {
- if(num_poss > 8)
- {
- row = 2;
- start_page--;
- if(start_page < 1)start_page = num_poss;
- load_vars(S.VAR_vid, display, start_page, num_poss);
- }
- else
- {
- row = 9;
- select_num = 8;
- start_page = 1;
- }
- }
- break;
- case KB_RIGHTARROW:
- case KB_RETURN:
- case KB_PAD_ENTER:
- col_field++;
- scroll = FALSE;
- next_field(&col_field, &select_num, &start_page, &row, &scroll,
- num_poss);
- if(scroll)
- load_vars(S.VAR_vid, display, start_page, num_poss);
- break;
- case KB_LEFTARROW:
- case KB_BACKFIELD:
- col_field--;
- scroll = FALSE;
- next_field(&col_field, &select_num, &start_page, &row, &scroll,
- num_poss);
- if(scroll)
- load_vars(S.VAR_vid, display, start_page, num_poss);
- break;
- case KBF_POPUP:
- if(col_field == 1)
- {
- /*
- Select variables from a POP-UP
- */
- CDFLIST_menu_keydef(screen);
- CDFLIST_select_menu_item(S.VARSELECT_vid,
- S.MES_vid,&var_num, SELECT_display, num_poss+1, num_rows,
- num_cols, VARSELECT_ROW_PASTE, VARSELECT_COL_PASTE,
- MENU, &tcode);
- if(tcode == KB_CTRL_F)
- {
- rcode = CDFLIST_read_VAR(display, possible,
- num_poss, select, num_select);
- if(rcode == 0)
- CDFLIST_field_menu(screen, in_field_num);
- else
- {
- CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
- NORMAL, NOPAUSE);
- last_error = TRUE;
- tcode = CONTINUE;
- }
- }
- else if(tcode == KB_RETURN)
- {
- /*
- USER selected a variable
- */
- if(var_num == SELECT_ALL)
- {
- /*
- "SELECT ALL" option: loop thru all variables
- */
- start = 1;
- end = num_poss;
- select_num = 1;
- start_page = 1;
- select_all = TRUE;
- row = 2;
- init_var_display(display, num_poss);
- load_vid(S.VAR_vid, display, 0,
- VAR_NUM_ELEMENTS, VAR_label);
- }
- else
- {
- /*
- Selecting one variable
- */
- start = var_num - 1;
- end = var_num - 1;
- select_all = FALSE;
- }
- for(var_num = start; var_num <= end; var_num++)
- {
- field_num = select_num * 3 + col_field;
- len = strlen(SELECT_display[var_num].label);
- if(len > CDFLIST_MAX_VAR_LENGTH)len=CDFLIST_MAX_VAR_LENGTH;
- strncpy(temp, SELECT_display[var_num].label, len);
- temp[len] = '\0';
- if(!select_all)
- /*
- Check if current variable has been selected
- */
- ok = check_var(display, temp, num_poss);
- else
- ok = TRUE;
- if(!ok)
- {
- strcpy(mes,temp);
- strcat(mes,dup_mes);
- CDFLIST_put_message(S.MES_vid, mes, RINGBELL,
- NORMAL, NOPAUSE);
- last_error = TRUE;
- }
- else
- {
- erase_display(S.VAR_vid, row, col, row,
- VAR_COLUMNS-COL_OFFSET);
- /*
- Display selected variable
- */
- CDFLIST_put_select_row(S.VAR_vid, display, row,
- field_num-1, temp, len, REVERSE);
- /*
- Save selected variable
- */
- strcpy(display[field_num-1].label+
- (display[field_num-1].field_col-1), temp);
- if(initialfilters)
- /*
- Display VALIDMIN & VALIDMAX if system uses NSSDC_STANDARD
- */
- {
- if(possible[var_num-1].data_type == CDF_EPOCH)
- {
- if(possible[var_num-1].minmax_flag !=
- NOTTHERE)
- {
- /*
- Display EPOCH time
- */
- CDFLIST_put_TIME(S.VAR_vid, display, row,
- field_num-1+1, possible[var_num-1].min);
- CDFLIST_put_TIME(S.VAR_vid, display, row,
- field_num-1+2, possible[var_num-1].max);
- }
- }
- else
- {
- if(possible[var_num-1].data_type !=
- CDF_CHAR
- && possible[var_num-1].data_type !=
- CDF_UCHAR)
- {
- if(possible[var_num-1].minmax_flag !=
- NOTTHERE)
- {
- CDFLIST_put_value(S.VAR_vid, display,
- row, field_num-1+1,
- possible[var_num-1].min);
- CDFLIST_put_value(S.VAR_vid, display,
- row, field_num-1+2,
- possible[var_num-1].max);
- } /* VALIDMIN or VALIDMAX not found */
- } /* datatype not CDF_CHAR */
- } /* Not EPOCH data type */
- } /* is NSSDC_STANDARD */
- if(!select_all)
- col_field++;
- else
- col_field = 4;
- scroll = FALSE;
- next_field(&col_field, &select_num,
- &start_page, &row, &scroll, num_poss);
- if(scroll)
- load_vars(S.VAR_vid, display, start_page, num_poss);
- }
- }/*select loop*/
- /*
- Now scroll back up to the top
- */
- if(select_all && num_poss > 8)
- {
- for(i=0; i<7; i++)
- {
- start_page++;
- load_vars(S.VAR_vid, display, start_page,
- num_poss);
- }
- row = 2;
- start_page = 1;
- select_num = 1;
- }
- }/*KB_RETURN*/
- }
- else
- {
- bump = TRUE;
- /*
- USER wishes to select from a POP-UP menu of values for a variable
- EPOCH does not have a discrete set of values
- Find the variable that the USER wishes to select from
- */
- var_num = get_var_num(possible, mnemonic, num_poss);
- if(var_num != NOTTHERE)
- {
- if(possible[var_num].num_values == 0)
- {
- bump = FALSE;
- if(possible[var_num].data_type != CDF_CHAR &&
- possible[var_num].data_type != CDF_UCHAR)
- CDFLIST_put_message(S.MES_vid, no_discrete_mes,
- RINGBELL, NORMAL, PAUSE);
- else
- CDFLIST_put_message(S.MES_vid, string_mes, RINGBELL,
- NORMAL, PAUSE);
- }
- else
- {
- DIS_display = (struct vid_struct *)
- malloc(possible[var_num].num_values *
- sizeof(struct vid_struct));
- if(DIS_display == NULL)
- {
- exit_code = print_error(screen, BAD_MALLOC);
- if(exit_code == NOCONTINUE)ExitBAD;
- }
- /*
- Load in the values in the virtual display
- */
- CDFLIST_load_discrete(possible[var_num].char_value,
- possible[var_num].num_values, col_field,
- DIS_display, &dis_rows, &col_paste);
- #ifdef vms
- change_virtual_display(dis_rows, DIS_COLUMNS,
- S.DIS_vid, BORDER, BOLD);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- change_virtual_display(dis_rows, DIS_COLUMNS,
- &S.DIS_vid, BORDER, BOLD);
- #endif
-
- /*
- Select desired value
- */
- CDFLIST_menu_keydef(screen);
- CDFLIST_select_menu_item(S.DIS_vid,
- S.MES_vid, &val_num, DIS_display,
- possible[var_num].num_values, dis_rows, DIS_COLUMNS,
- DIS_ROW_PASTE, col_paste, MENU, &tcode);
- if(tcode == KB_CTRL_F)
- {
- rcode = CDFLIST_read_VAR(display, possible,
- num_poss, select, num_select);
- if(rcode == 0)
- CDFLIST_field_menu(screen, in_field_num);
- else
- {
- CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
- NORMAL, NOPAUSE);
- last_error = TRUE;
- tcode = CONTINUE;
- }
- }
- else if(tcode != QUIT)
- {
- CDFLIST_put_select_row(S.VAR_vid, display, row,
- field_num-1, DIS_display[val_num-1].label,
- MINMAX_SIZE-1, NORMAL);
- strcpy(display[field_num-1].label,
- DIS_display[val_num-1].label);
- }
- free(DIS_display);
- }
- }/*var_num there or not*/
- if(bump)
- {
- col_field++;
- scroll = FALSE;
- next_field(&col_field, &select_num,
- &start_page, &row, &scroll, num_poss);
- if(scroll)
- load_vars(S.VAR_vid, display, start_page,
- num_poss);
- }
- }
- break;
- case KB_CTRL_F:
- rcode = CDFLIST_read_VAR(display, possible, num_poss,
- select, num_select);
- if(rcode == 0)
- CDFLIST_field_menu(screen, in_field_num);
- else
- {
- CDFLIST_put_message(S.MES_vid, min_gt_max, RINGBELL,
- NORMAL, NOPAUSE);
- last_error = TRUE;
- tcode = CONTINUE;
- }
- break;
- case KB_REDRAW:
- repaint_screen();
- break;
- case KB_DELETE:
- erase_display(S.VAR_vid, row, col, row, VAR_COLUMNS-COL_OFFSET);
- /*
- Delete current variable
- */
- display[field_num-1].label[display[field_num-1].field_col-1]='\0';
- display[field_num-1+1].label[0]='\0';
- display[field_num-1+2].label[0]='\0';
- break;
- }
- }
- }
-
-
-
-
-
-
-